<template>
  <div>
    <div style="margin: 10px 0">
      <el-button type="primary" @click="handleAdd">新增 <i class="el-icon-circle-plus-outline"></i></el-button>
    </div>
    <el-table :data="tableData" border stripe :header-cell-class-name="'headerBg'"  >
        <el-table-column prop="platform" label="平台" width="140"></el-table-column>
        <el-table-column prop="url" label="url" ></el-table-column>
        <el-table-column  label="是否开启" width="120" align="center">
          <template slot-scope="scope">
            <el-tag :type="scope.row.needNotify ? 'success' : 'danger'" >{{scope.row.needNotify ? '启用' : '未启用'}}</el-tag>
          </template>
        </el-table-column>
      <el-table-column label="操作"  width="200" align="center">
        <template slot-scope="scope">
          <el-button type="success" @click="handleEdit(scope.row)">编辑 <i class="el-icon-edit"></i></el-button>
          <el-popconfirm
              class="ml-5"
              confirm-button-text='确定'
              cancel-button-text='我再想想'
              icon="el-icon-info"
              icon-color="red"
              title="您确定删除吗？"
              @confirm="del(scope.row)"
          >
            <el-button type="danger" slot="reference">删除 <i class="el-icon-remove-outline"></i></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="webhook" :visible.sync="dialogFormVisible" width="30%" >
      <el-form label-width="80px" size="small">
        <el-form-item label="平台">
          <el-input v-model="form.platform" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="URL">
          <el-input v-model="form.url" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="是否开启">
          <el-switch
              v-model="form.needNotify"
              active-color="#13ce66"
              inactive-color="#ff4949">
          </el-switch>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "WebhookConfig",
  data(){
    return{
      tableData:[],
      dialogFormVisible:false,
      form:{}
    }
  },
  created() {
    this.load()
  },
  methods:{
    handleEdit(row) {
      this.form = JSON.parse(JSON.stringify(row))
      this.dialogFormVisible = true
    },
    save(){
      this.request.post("/config/setWebhookConfig",this.form).then(res => {
        if (res.code === '0') {
          this.$message.success("保存成功")
          this.dialogFormVisible = false
          this.load()
        } else {
          this.$message.error("保存失败")
        }
      })
    },
    handleAdd() {
      this.dialogFormVisible = true
      this.form = {}
    },
    load(){
      this.request.get("/config/getWebhookConfig").then(res => {
        this.tableData = res.data
      })
    }
  }
}
</script>


<style scoped>

</style>